//package com.fecean.aabbc.netty.handler5;
//
//import com.fecean.aabbc.netty.message5.MessageBuilder;
//import com.fecean.aabbc.netty.message5.MessageTypeEnum;
//import com.fecean.aabbc.netty.message5.ResponseFuture;
//import io.netty.channel.ChannelHandler;
//import io.netty.channel.ChannelHandlerContext;
//import io.netty.channel.ChannelInboundHandlerAdapter;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//
//import java.util.Map;
//import java.util.concurrent.ConcurrentHashMap;
//
///**
// * NettyResponseChannelHandler
// *
// * @author: chenfenghai
// * @version: 1.0
// * @date: 2020-03-05 15:59
// * @blame Team
// */
//@Slf4j
//@Component
//@ChannelHandler.Sharable
//public class NettyResponseChannelHandler extends ChannelInboundHandlerAdapter {
//
//    private static final Map<String, ResponseFuture> RESPONSE_FUTURE_MAP = new ConcurrentHashMap<>();
//
//    public void addResponseFuture(String id, ResponseFuture responseFuture){
//        RESPONSE_FUTURE_MAP.putIfAbsent(id, responseFuture);
//    }
//
//    @Override
//    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
//        MessageBuilder messageBuilder = MessageBuilder.readMessage(msg);
//        if(messageBuilder.isMessage(MessageTypeEnum.RESPONSE)){
//            log.info("客户端[{}-{}]收到响应：{}", messageBuilder.getMessage().getTenant(),
//                    messageBuilder.getMessage().getCinema(), messageBuilder.getResponseMessage());
//
//            if(RESPONSE_FUTURE_MAP.containsKey(messageBuilder.getMessage().getId())){
//                RESPONSE_FUTURE_MAP.get(messageBuilder.getMessage().getId()).setResponse(messageBuilder.getResponseMessage());
//                RESPONSE_FUTURE_MAP.remove(messageBuilder.getMessage().getId());
//            }
//            return;
//        }
//        ctx.fireChannelRead(msg);
//    }
//}
